package o;

import android.database.MatrixCursor;
import android.database.MatrixCursor.RowBuilder;
import com.huawei.hms.common.data.DataBufferSafeParcelable;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

public final class euj {
    public static final String ॱ = (ContentManager.getInstant().getContext().getPackageName() + ".imageservice.CONTENT_URI");

    private static File ˊ(String str) {
        if (str != null) {
            return ere.ˋ(str);
        }
        Logger.ˋ("ImageProviderUtil", "iconToken is null");
        return null;
    }

    private static synchronized MatrixCursor ˏ(String str, int i) {
        MatrixCursor matrixCursor;
        Exception e;
        Throwable th;
        synchronized (euj.class) {
            File ˊ = ˊ(str);
            if (ˊ != null && ˊ.exists() && ˊ.isFile()) {
                matrixCursor = new MatrixCursor(new String[]{"position", "blocklength", "length", DataBufferSafeParcelable.DATA_FIELD}, 1);
                RowBuilder newRow = matrixCursor.newRow();
                newRow.add(Integer.valueOf(i));
                int length = (int) ˊ.length();
                FileInputStream fileInputStream;
                try {
                    Object obj = new byte[5000];
                    fileInputStream = new FileInputStream(ˊ);
                    try {
                        if (Long.valueOf(fileInputStream.skip((long) i)).longValue() != -1) {
                            int read = fileInputStream.read(obj, 0, 5000);
                            if (read != -1) {
                                newRow.add(Integer.valueOf(read));
                                newRow.add(Integer.valueOf(length));
                                newRow.add(obj);
                            } else {
                                newRow.add(Integer.valueOf(0));
                                newRow.add(Integer.valueOf(length));
                                newRow.add(null);
                            }
                            if (fileInputStream != null) {
                                try {
                                    fileInputStream.close();
                                } catch (IOException e2) {
                                    Logger.ˋ("ImageProviderUtil", "getImageData(String iconToken, int position) " + e2.toString());
                                }
                            }
                        } else if (fileInputStream != null) {
                            try {
                                fileInputStream.close();
                            } catch (IOException e22) {
                                Logger.ˋ("ImageProviderUtil", "getImageData(String iconToken, int position) " + e22.toString());
                            }
                        }
                    } catch (Exception e3) {
                        e = e3;
                        try {
                            Logger.ˋ("ImageProviderUtil", "read imagefile error: " + e.toString());
                            if (fileInputStream != null) {
                                try {
                                    fileInputStream.close();
                                } catch (IOException e222) {
                                    Logger.ˋ("ImageProviderUtil", "getImageData(String iconToken, int position) " + e222.toString());
                                }
                            }
                            return matrixCursor;
                        } catch (Throwable th2) {
                            th = th2;
                            if (fileInputStream != null) {
                                try {
                                    fileInputStream.close();
                                } catch (IOException e2222) {
                                    Logger.ˋ("ImageProviderUtil", "getImageData(String iconToken, int position) " + e2222.toString());
                                }
                            }
                            throw th;
                        }
                    }
                } catch (Exception e4) {
                    Exception exception = e4;
                    fileInputStream = null;
                    e = exception;
                    Logger.ˋ("ImageProviderUtil", "read imagefile error: " + e.toString());
                    if (fileInputStream != null) {
                        fileInputStream.close();
                    }
                    return matrixCursor;
                } catch (Throwable th3) {
                    th = th3;
                    fileInputStream = null;
                    if (fileInputStream != null) {
                        fileInputStream.close();
                    }
                    throw th;
                }
            }
            matrixCursor = null;
        }
        return matrixCursor;
    }

    public static MatrixCursor ˏ(String str, int i, String str2) {
        MatrixCursor ˏ = ˏ(str, i);
        if (str2 == null) {
            Logger.ˏ("ImageProviderUtil", "getImageData iconUrl is null.");
        }
        if (str2 == null || ˏ != null) {
            return ˏ;
        }
        Logger.ˏ("ImageProviderUtil", "getImageData cursor not exsit, iconUrl not null,will loadImageFile by Glide again,");
        if (eqx.ˎ(ContentManager.getInstant().getContext(), str2) != null) {
            return ˏ(str, i);
        }
        return ˏ;
    }
}
